package com.thinkfit.jy.presenter;

import com.common.lib.bean.VersionBean;
import com.common.lib.mvp.BasePresenter;
import com.common.lib.network.HttpListener;
import com.common.lib.network.HttpMethods;
import com.common.lib.network.HttpObserver;
import com.thinkfit.jy.BuildConfig;
import com.thinkfit.jy.contract.VersionContract;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class VersionPresenter extends BasePresenter<VersionContract.View> implements VersionContract.Presenter {

    public VersionPresenter(@NotNull VersionContract.View rootView) {
        super(rootView);
    }

    @Override
    public void getVersion() {
        HttpMethods.Companion.getInstance().checkVer(BuildConfig.VERSION_CODE, 29,
                new HttpObserver(getRootView(), new HttpListener<VersionBean>() {
                    @Override
                    public void onSuccess(@Nullable VersionBean bean) {
                        if (getRootView() == null) {
                            return;
                        }
                        getRootView().getVersionSuccess(bean);
                    }

                    @Override
                    public void dataError(@Nullable int code, @Nullable String msg) {
                        if (getRootView() == null) {
                            return;
                        }
                        getRootView().showErrorDialog(code, msg);
                    }

                    @Override
                    public void connectError(@Nullable Throwable e) {
                        if (getRootView() == null) {
                            return;
                        }
                        getRootView().showErrorDialog(-1, "");
                    }
                }, getCompositeDisposable()));
    }

    @Override
    public void getAdvert() {

    }

    @Override
    public void getVideoList(int type) {

    }
}
